﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Workflow.Common.ExcelHelp;
using Workflow.Common.FileUtil;
using Workflow.Common.mail;
using Workflow.IService;
using Workflow.Service;
using Workflow.Web.Common;
using Spring.Context.Support;
using Workflow.Model;
using System.Drawing;

namespace Workflow.Web.Controllers
{
    [Localization]
    [UserAuthorize]
    public class ServiceTestController : Controller
    {

        //
        // GET: /ServiceTest/

    	public IUserManager UserManager { get; set; }
		public IDistributeService DistributeService { get; set; }
        public ActionResult ShowTest()
        {
            User user = UserManager.GetUser(1);
            ViewData["TestMessage"] = "User Name :" + user.UserName;
			MailHelper webMail = new MailHelper();

			webMail.SendMail("1", "pwd", "xintang.zheng@genpact.com", new[] { "xintang.zheng@genpact.com" }, new string[] { },  "test", "test", new string[] { });

			//ExcelEdit edit = new ExcelEdit();
			//edit.Open("d:\\TEST.xls");
			//var t =edit.GetSheet("Sheet1");
			//edit.SetCellValue(t, 1, 1, "111");
			//edit.app.Visible = true;

        	//FileUtil.CopyFolder("d:\\1", "d:\\2");
        	//var dd = FileUtil.GetAllFile("d:\\1");
			//long i = 0;
			//IList<Case> temp = CaseService.GetAllCaseByPage(out i, 1, 20, null, "OrderBy", "CaseNo");
			
			
			//DistributeService.UpdateCaseForDistribute(temp,user);
            return View();
        }
		public ActionResult GetClassA()
		{
			string pm = Request["id"];
			var date = "";// CaseService.GetFolderClass(pm);

			//string d = "[{\"id\":1,\"text\":\"Java\"}]";

			return Json(date, "text/plain", JsonRequestBehavior.AllowGet);
			//return this.Content(d);
		}
		
		public ActionResult GetImage()
		{


			Image img1 = Image.FromFile(System.Web.HttpContext.Current.Request.PhysicalApplicationPath+ "tiff\\1.tif");

			Guid guid = img1.FrameDimensionsList[0];

			System.Drawing.Imaging.FrameDimension dimension = new

			System.Drawing.Imaging.FrameDimension(guid);

			int nTotFrame = img1.GetFrameCount(dimension);



			//save all frame

			int nLoop = 0;

			

			img1.SelectActiveFrame(dimension, 2);

				

			//System.Drawing.Image image = System.Drawing.Image.FromFile("d:\\1.tif");

			System.IO.MemoryStream Ms = new MemoryStream();
			img1.Save(Ms, System.Drawing.Imaging.ImageFormat.Jpeg);
			byte[] img = new byte[Ms.Length];
			Ms.Position = 0;
			Ms.Read(img, 0, Convert.ToInt32(Ms.Length));
			Ms.Close();
			return File(img, "image/jpeg");
		}
    }
}
